/*
 * Created on 2005-4-17
 *
 */
package com.nauu.atombuilder.commands;

import java.util.Iterator;
import java.util.Map;

import org.eclipse.gef.commands.Command;

import com.nauu.atombuilder.modle.Guide;
import com.nauu.atombuilder.modle.Node;
import com.nauu.atombuilder.modle.Ruler;

/**
 * @author Administrator
 *
 */
public class DeleteGuideCommand extends Command {

    private Guide guide;

    private Ruler ruler;

    private Map oldParts;

    public DeleteGuideCommand(Guide guide, Ruler ruler) {
        setLabel("Delete Guide");
        this.guide = guide;
        this.ruler = ruler;
    }

    public void execute() {
        oldParts = guide.getMap();
        Iterator iter = oldParts.keySet().iterator();
        while (iter.hasNext()) {
            guide.detachPart((Node) iter.next());
        }
        ruler.getGuides().remove(guide);
    }

    public void redo() {
        super.redo();
    }

    public void undo() {
        ruler.getGuides().add(guide);
        Iterator iter = oldParts.keySet().iterator();
        while (iter.hasNext()) {
            Node node = (Node)iter.next();
            guide.attachPart(node, ((Integer)oldParts.get(node)).intValue());
        }
    }

}
